package kotlinx.coroutines.script

import android.graphics.Rect
import abc.reflect.App
import v9.assist.analyst.selfInSmallMap

// 区块
data class Block(
    val name: String,
    val left: Int,
    val top: Int,
    val width: Int,
    val height: Int,
    val remark: String = "",
) {
    val right = left + width
    val bottom = top + height
    val x = left + width / 2
    val y = top + height / 2
    val rect by lazy { Rect(left, top, right, bottom) }

    override fun toString(): String {
        //return "[$name#l:${(left / 1f.pt).toInt()}#t:${(top / 1f.pt).toInt()}#w:${(width / 1f.pt).toInt()}#h:${(height / 1f.pt).toInt()}]"
        return "[$name#l:${(left)}#t:${(top)}#r:${(right)}#b:${(bottom)}]"
    }

    fun contains(x: Int, y: Int): Boolean {
        return x in left until right && y in top until bottom
    }

//    fun click(invokingTime: Long = XGesturePoint.tapTime, startDelay: Long): XGesturePoint {
//        val x = left + random.nextInt(width + 1)
//        val y = top + random.nextInt(height + 1)
//        return XGesturePoint(name = name, type = 0, points = listOf(Pair(x, y),
//            Pair(x, y)), time = invokingTime, startDelay = startDelay)
//    }

    fun calcAngleBySmallMap(): Int {
        val offsetX = x - selfInSmallMap.x
        val offsetY = y - selfInSmallMap.y
        return  App.take().pointToAngle(offsetX, offsetY)
    }

}